import HTTP from '../http'
import { URL } from '@/config'
import { IAsideListData, IEditData, IFileListMData } from '@/typing'

export default class FileManageModel extends HTTP {
  // 获取侧边栏列表数据
  getAsideList() {
    return new Promise<any>((resolve, reject) => {
      this.axiosGet({
        url: URL.GET_ASIDE_LIST,
        success(res: IAsideListData) {
          resolve(res.data.list)
        },
        error(err: never) {
          reject(err)
        }
      })
    })
  }
  // 获取文件列表数据
  getFileList() {
    return new Promise<any>((resolve, reject) => {
      this.axiosGet({
        url: URL.GET_FILE_LIST,
        success(res: IFileListMData) {
          resolve(res.data)
        },
        error(err: never) {
          reject(err)
        }
      })
    })
  }
  // 上传文件
  addFileData(data: any) {
    return new Promise<any>((resolve, reject) => {
      this.axiosPostFile({
        url: URL.ADD_FILE_DATA,
        data,
        success(res: any) {
          resolve(res)
        },
        error(err: never) {
          reject(err)
        }
      })
    })
  }
  // 删除数据
  DFileData(id: number) {
    return new Promise<any>((resolve, reject) => {
      this.axiosDelete({
        url: URL.DELETE_FILE_ID,
        data: { id },
        success(res: any) {
          resolve(res)
        },
        error(err: never) {
          reject(err)
        }
      })
    })
  }
  // 修改数据
  EFileData(editData: IEditData) {
    return new Promise<any>((resolve, reject) => {
      this.axiosPut({
        url: URL.EDIT_FILE_DATA,
        data: editData,
        success(res: any) {
          resolve(res)
        },
        error(err: never) {
          reject(err)
        }
      })
    })
  }
}
